<template>
	<view class="list">
		<zzx-tabs :items="items" :current="current" @clickItem="onClickItem" ref="mytabs" :activeColor='activeColor'
		 :defaultColor="defaultColor">
		</zzx-tabs>
		<view v-show="current === 0">
			<view>
				<!-- 商品列表信息 -->
				<view class="pla-body" @click="hanldRegInfo(item,0)" v-for="(item,index) in applyList">
					<view class="infosetting">
						<text>订单编号：{{item.order_no}}</text>
						<text style="color: #FF5F49;">{{item.status_text}}</text>
					</view>
					<view class='img-list'>
						<view class="pla-img">
							<image :src="item.image"></image>
						</view>
						<view class="pla-info">
							<view class="ply-name">{{item.title}}</view>
							<view class="ply-list-item">
								<text>￥{{item.payment}}</text>
								<text style="color: #999999;">×1</text>
							</view>
						</view>

					</view>
					<view class="count" style="padding: 10px;border-top: 1px solid #EFEFF4;">
						<view style="font-size: 13px;color: #999999;">共<text style="color: #333333;">1</text>个商品</view>
						<view style="font-size: 14px;color: #333333;padding-left: 10px;">合计：￥{{item.payment}} </view>
					</view>
					<view class="ex-but" v-if='item.status==0'>
						<view class="ex-no" @tap.stop="hanldNo(item.id)">取消报名</view>
						<view class="ex-yes" @tap.stop="hanldPaly(item.id)">立即付款</view>
					</view>
				</view>

				<uni-load-more :status="loadStatus"></uni-load-more>


			</view>
		</view>
		<view v-show="current === 1">
			<view>
				<!-- 商品列表信息 -->
				<view class="pla-body" @click="hanldRegInfo(item,1)" v-for="(item,index) in applyList1">
					<view class="infosetting">
						<text>订单编号：{{item.order_no}}</text>
						<text style="color: #FF5F49;">{{item.status_text}}</text>
					</view>
					<view class='img-list'>
						<view class="pla-img">
							<image :src="item.image"></image>
						</view>
						<view class="pla-info">
							<view class="ply-name">{{item.title}}</view>
							<view class="ply-list-item">
								<text>￥{{item.payment}}</text>
								<text style="color: #999999;">×1</text>
							</view>
						</view>
					</view>
					<view class="count" style="padding: 10px;border-top: 1px solid #EFEFF4;">
						<view style="font-size: 13px;color: #999999;">共<text style="color: #333333;">1</text>个商品</view>
						<view style="font-size: 14px;color: #333333;padding-left: 10px;">合计：￥{{item.payment}}</view>
					</view>
					<view class="ex-but" v-if='item.status==0'>
						<view class="ex-no" @tap.stop="hanldNo(item.id)">取消报名</view>
						<view class="ex-yes" @tap.stop="hanldPaly(item.id)">立即付款</view>
					</view>
				</view>

				<uni-load-more :status="loadStatus1"></uni-load-more>

			</view>

		</view>

		<view v-show="current === 2">
			<view>
				<!-- 商品列表信息 -->
				<view class="pla-body" @click="hanldRegInfo(item,2)" v-for="(item,index) in applyList2">
					<view class="infosetting">
						<text>订单编号：{{item.order_no}}</text>
						<text style="color: #FF5F49;">{{item.status_text}}</text>
					</view>
					<view class='img-list'>
						<view class="pla-img">
							<image :src="item.image"></image>
						</view>
						<view class="pla-info">
							<view class="ply-name">{{item.title}}</view>
							<view class="ply-list-item">
								<text>￥{{item.payment}}</text>
								<text style="color: #999999;">×1</text>
							</view>
						</view>
					</view>
					<view class="count" style="padding: 10px;border-top: 1px solid #EFEFF4;">
						<view style="font-size: 13px;color: #999999;">共<text style="color: #333333;">1</text>个商品</view>
						<view style="font-size: 14px;color: #333333;padding-left: 10px;">合计：￥{{item.payment}} 积分</view>
					</view>
					<view class="ex-but" v-if='item.status==1'>
						<view class="ex-no" @tap.stop="hanldNo(item.id,true)" style="margin-right:0">取消报名</view>
					</view>

				</view>
				<uni-load-more :status="loadStatus2"></uni-load-more>
			</view>
		</view>

		<view v-show="current === 3">
			<view>
				<!-- 商品列表信息 -->
				<view class="pla-body" @click="hanldRegInfo(item,3)" v-for="(item,index) in applyList3">
					<view class="infosetting">
						<text>订单编号：{{item.order_no}}</text>
						<text style="color: #FF5F49;">{{item.status_text}}</text>
					</view>
					<view class='img-list'>
						<view class="pla-img">
							<image :src="item.image"></image>
						</view>
						<view class="pla-info">
							<view class="ply-name">{{item.title}}</view>
							<view class="ply-list-item">
								<text>￥{{item.payment}}</text>
								<text style="color: #999999;">×1</text>
							</view>
						</view>
					</view>
					<view class="count" style="padding: 10px;border-top: 1px solid #EFEFF4;">
						<view style="font-size: 13px;color: #999999;">共<text style="color: #333333;">1</text>个商品</view>
						<view style="font-size: 14px;color: #333333;padding-left: 10px;">合计：￥{{item.payment}}</view>
					</view>

				</view>
				<uni-load-more :status="loadStatus3"></uni-load-more>
			</view>
		</view>
	</view>
</template>

<script>
	import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue"
	import zzxTabs from "@/components/zzx-tabs/zzx-tabs.vue"
	export default {
		data() {
			return {
				items: ['全部', '待付款', '待参与', '已完成'],
				activeColor: '#333333',
				defaultColor: '#999999',
				current: 0,
				loadStatus: 'more',
				page: 1,
				applyList: [],

				//付款
				loadStatus1: 'more',
				page1: 1,
				applyList1: [],

				//待参
				loadStatus2: 'more',
				page2: 1,
				applyList2: [],

				//已完
				loadStatus3: 'more',
				page3: 1,
				applyList3: [],

				status: "", //状态
				idnumber: 1,
				idnumber1: 1,
				idnumber2: 1,
				idnumber3: 1
			}
		},
		onReachBottom() {
			console.log(this.idnumber + "this.idnumber")
			if (this.loadStatus === 'more' && this.idnumber == 1) {
				this.gettApplyList(true)
			}
			if (this.loadStatus1 === 'more' && this.idnumber1 == 1) {
				this.gettApplyFKList(true)
			}
			if (this.loadStatus2 === 'more' && this.idnumber2 == 1) {
				this.gettApplyCYList(true)
			}
			if (this.loadStatus3 === 'more' && this.idnumber3 == 1) {
				this.gettApplyYWList(true)
			}
		},
		onLoad(option) {
			this.gettApplyList();
			console.log(option.id + "传递id")
			if (option.id) {
				let id = option.id;
				this.idnumber = id;
				if (id == 0) {
					this.page = 1;
					this.applyList = [];
					this.gettApplyList()
				}
				if (id == 1) {
					this.page1 = 1;
					this.applyList1 = [];
					this.gettApplyFKList();
					this.current = 1;
				}
				if (id == 2) {
					this.page2 = 1;
					this.applyList2 = [];
					this.gettApplyCYList();
					this.current = 2;
				}
				if (id == 3) {
					this.page3 = 1;
					this.applyList3 = [];
					this.gettApplyYWList();
					this.current = 3;
				}
			}
		},
		components: {
			uniLoadMore
		},
		methods: {
			//取消报名
			onClickItem(e) {
				if (this.current !== e.currentIndex) {
					this.current = e.currentIndex;
					if (e.currentIndex == 0) { //全部
						this.page = 1;
						this.gettApplyList()
					}

					if (e.currentIndex == 1) { //代付款
						this.page1 = 1;
						this.gettApplyFKList()
					}

					if (e.currentIndex == 2) { //代参与
						this.page2 = 1;
						this.gettApplyCYList()
					}

					if (e.currentIndex == 3) { //已完
						this.page3 = 1;
						this.gettApplyYWList()
					}


				}
			},
			//立即报名
			//微信支付
			hanldPaly(id) {
				uni.showLoading({
					title: '加载中'
				});
				let that = this;
				const formData = {
					id: id
				}
				this.$http.post('/wechat/wxPay', formData).then((response) => {
					const res = response.data;
					if (res.code == 0) {
						wx.requestPayment({
							timeStamp: res.data.timeStamp,
							nonceStr: res.data.nonceStr,
							package: res.data.package,
							signType: "MD5",
							paySign: res.data.paySign,
							success(res) {
								that.page = 1;
								that.applyList = [];
								that.page1 = 1;
								that.applyList1 = [];
								that.page2 = 1;
								that.applyList2 = [];
								that.page3 = 1;
								that.applyList3 = [];
								that.gettApplyList();
								that.gettApplyFKList();
								uni.showToast({
									title: res.msg,
									icon: 'none'
								});
								console.log(res + "支付接口");
							},
							fail(res) {
								uni.showToast({
									title: res.msg,
									icon: 'none'
								});
							}
						});
					}
					uni.showToast({
						title: res.msg,
						icon: 'none'
					});
					uni.hideLoading();
				})
			},
			hanldRegInfo(item, id) {
				let aa = item;
				let bb = JSON.stringify(aa)
				let cc = encodeURIComponent(bb);
				// console.log(bb);
				// console.log(cc)
				console.log(id)
				// url: `/pages/find/apply?id=${id}&img=${this.formData.image}&title=${this.formData.title}&subtitle=${this.formData.subtitle}&price=${this.formData.price}`
				uni.navigateTo({
					url: `/pages/user/regiInfo?address=${cc}&id=${id}`
				})

			},
			//取消
			hanldNo(id, join = 0) {
				const formData = {
					id: id,
				}
				this.$http.post('/activity/cancel', formData).then((response) => {
					const res = response.data;
					if (res.code == 0) {
						console.log(res)
						uni.showToast({
							title: res.msg,
							icon: 'none'
						});
						this.page = 1;
						this.applyList = [];
						this.page1 = 1;
						this.applyList1 = [];
						this.page2 = 1;
						this.applyList2 = [];
						this.page3 = 1;
						this.applyList3 = [];
						this.gettApplyList();
						if (join) {
							this.gettApplyCYList();

						} else {
							this.gettApplyFKList();
						}
					}else{
						uni.showToast({
							title: res.msg,
							icon: 'none'
						});
					}
				})
			},
			//列表---全部
			gettApplyList(type) {
				if (!type) {
					this.page = 1;
				}
				const params = {
					status: this.status,
					page: this.page
				}
				this.loadStatus = 'loading'
				this.$http.get('/activity/order', {
					params: params
				}).then((response) => {
					const res = response.data;
					console.log(res)
					if (res.code == 0) {
						if (this.page > res.data.last_page) {
							// 没有数据了
							this.loadStatus = 'noMore'
						} else {
							// 未加载完毕
							this.loadStatus = 'more'
							this.page++
						}
						console.log(type)
						if (type) {
							this.applyList = [...this.applyList, ...res.data.data];
						} else {
							this.applyList = res.data.data
						}
					} else {}
				})
			},

			//列表---代付款
			gettApplyFKList(type) {
				if (!type) {
					this.page1 = 1;
				}
				const params = {
					status: 0,
					page: this.page1,
				}
				this.loadStatus1 = 'loading'
				this.$http.get('/activity/order', {
					params: params
				}).then((response) => {
					const res = response.data;
					console.log(res)
					if (res.code == 0) {
						if (this.page1 > res.data.last_page) {
							// 没有数据了
							this.loadStatus1 = 'noMore'
						} else {
							// 未加载完毕
							this.loadStatus1 = 'more'
							this.page1++
						}
						console.log(type)
						if (type) {
							this.applyList1 = [...this.applyList1, ...res.data.data];
						} else {
							this.applyList1 = res.data.data
						}
					} else {}
				})
			},

			//列表---代参与
			gettApplyCYList(type) {
				if (!type) {
					this.page2 = 1;
				}
				const params = {
					status: 1,
					page: this.page2,
				}
				this.loadStatus2 = 'loading'
				this.$http.get('/activity/order', {
					params: params
				}).then((response) => {
					const res = response.data;
					console.log(res)
					if (res.code == 0) {
						if (this.page2 > res.data.last_page) {
							// 没有数据了
							this.loadStatus2 = 'noMore'
						} else {
							// 未加载完毕
							this.loadStatus2 = 'more'
							this.page2++
						}
						console.log(type)
						if (type) {
							this.applyList2 = [...this.applyList2, ...res.data.data];
						} else {
							this.applyList2 = res.data.data
						}
					} else {}
				})
			},

			//列表---已完
			gettApplyYWList(type) {
				if (!type) {
					this.page3 = 1;
				}
				const params = {
					status: 3,
					page: this.page3,
				}
				this.loadStatus3 = 'loading'
				this.$http.get('/activity/order', {
					params: params
				}).then((response) => {
					const res = response.data;
					console.log(res)
					if (res.code == 0) {
						if (this.page3 > res.data.last_page) {
							// 没有数据了
							this.loadStatus3 = 'noMore'
						} else {
							// 未加载完毕
							this.loadStatus3 = 'more'
							this.page3++
						}
						console.log(type)
						if (type) {
							this.applyList3 = [...this.applyList3, ...res.data.data];
						} else {
							this.applyList3 = res.data.data
						}
					} else {}
				})
			},
		}
	}
</script>

<style scoped>
	.list {
		width: 100%;
	}

	.list>>>.zzx-tabs-bar {
		display: none;
	}

	.list>>>.zzx-tabs .zzx-tabs-bar .zzx-bottom-line {
		display: none;
	}


	.list>>>.zzx-tabs {
		padding: 5px 0;
		background-color: #fff;
	}

	/**/
	.pla-body {
		margin: 10px 16px 10px 16px;
		border-radius: 4px;
		background-color: #fff;
		padding-bottom: 10px;
	}

	.img-list {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
	}

	.pla-img {
		margin: 10px;
	}

	.pla-img image {
		width: 90px;
		height: 90px;
		border-radius: 4px;
	}

	.infosetting {
		padding: 12px 8px;
		border-bottom: 1px solid #EFEFF4;
		color: #333333;
		font-size: 13px;
		display: flex;
		flex-direction: row;
		width: 100%;
		justify-content: space-between;
	}

	.pla-num {
		width: 105px;
		padding-top: 10px;
		text-align: right;
		padding-right: 10px;
	}

	.ply-name {
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
		color: #333333;
		font-weight: bold;
		font-size: 12px;
	}

	.pla-info {
		width: 480upx;
		display: flex;
		flex-direction: column;
		justify-content: center;
	}

	.count {
		display: flex;
		flex-direction: row;
		justify-content: flex-end;
		color: #999999;
		padding: 0 10px;
		align-items: center;
	}

	.red-price {
		font-size: 16px;
	}

	.ex-but {
		display: flex;
		justify-content: flex-end;
		padding-right: 10px;
	}

	.ex-no {
		width: 158upx;
		height: 60upx;
		border-radius: 30px;
		border: 1px solid rgba(239, 239, 244, 1);
		color: #333333;
		line-height: 58upx;
		text-align: center;
		font-size: 13px;
		margin-right: 10px;
	}

	.ex-yes {
		width: 158upx;
		height: 60upx;
		border-radius: 30px;
		border: 1px solid rgba(255, 95, 73, 1);
		color: #FF5F49;
		line-height: 58upx;
		text-align: center;
		font-size: 13px;
	}

	.ply-list-item {
		color: #666666;
		font-size: 12px;
		padding-top: 10px;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		padding-right: 15px;
	}
</style>
